// 获取用户排行榜列表
const cloud = require('wx-server-sdk')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

const db = cloud.database()

exports.main = async (event, context) => {
  try {
    // 获取所有用户数据，按分数降序排列
    const result = await db.collection('users')
      .orderBy('score', 'desc')
      .get()
    
    return {
      success: true,
      data: result.data,
      total: result.data.length
    }
  } catch (error) {
    console.error('获取用户列表失败:', error)
    return {
      success: false,
      error: error.message
    }
  }
}
